package com.java.Stream;

import java.util.*;
import java.util.stream.Stream;

public class CreateAPI {
    public static void main(String[] args) {
        // 单列结合：Collection中的stream()和parallelStream()分别创建串行流和并行流
        List list = new ArrayList();
        Collections.addAll(list, 1, 2, 3, 4, 5, 6, 7);
        list.stream().forEach(item -> System.out.print(item + " ")); // 1 2 3 4 5 6 7
        System.out.println();
        
        Set set = new HashSet();
        Collections.addAll(set, 1, 2, 3, 4, 5, 6, 7);
        set.stream().forEach(item -> System.out.print(item + " ")); // 1 2 3 4 5 6 7
        System.out.println();
        
        // 双列集合：不能直接创建，需先通过keySey()或entrySet()或values()转为单列结合后创建
        HashMap hashMap = new HashMap();
        hashMap.put(1, "A");
        hashMap.put(2, "B");
        hashMap.put(3, "C");
        hashMap.keySet().stream().forEach(item -> System.out.print(item + " ")); // 1 2 3
        System.out.println();
        hashMap.entrySet().stream().forEach(item -> System.out.print(item + " ")); // 1=A 2=B 3=C
        System.out.println();
        hashMap.values().stream().forEach(item -> System.out.print(item + " ")); // A B C
        System.out.println();
        
        // 数组：Arrays中的stream()或Stream中的of()创建
        String[] array = {"1", "2", "3", "4", "5", "6", "7"};
        Arrays.stream(array).forEach(item -> System.out.print(item + " ")); // 1 2 3 4 5 6 7
        System.out.println();
        Stream.of(array).forEach(item -> System.out.print(item + " ")); // 1 2 3 4 5 6 7
        System.out.println();
        
        // 零散数据：Stream中的of()创建
        Stream.of(1, 2, 3, 4, "5", "6", "7").forEach(item -> System.out.print(item + " ")); // 1 2 3 4 5 6 7
        System.out.println();
        
        // Stream.of⭐⭐⭐：若参数为基本数据类型数组，那么该数组整个将被一个元素
        Stream.of(new int[]{1, 2, 3, 4, 5, 6, 7}).forEach(item -> System.out.print(item + " ")); // [I@404b9385
        System.out.println();
        Stream.of(new String[]{"1", "2", "3", "4", "5", "6", "7"}).forEach(item -> System.out.print(item + " ")); // 1 2 3 4 5 6 7
        System.out.println();
        Stream.of(1, 2, 3, 4, 5, 6, 7).forEach(item -> System.out.print(item + " ")); // 1 2 3 4 5 6 7
        System.out.println();
        Stream.of("1", "2", "3", "4", "5", "6", "7").forEach(item -> System.out.print(item + " ")); // 1 2 3 4 5 6 7
        System.out.println();
        
        // 空流：Stream中的empty()创建
        Stream.empty().forEach(item -> System.out.print(item + " "));
        System.out.println();
    }
}
